// 忘记密码中确认账号组件

import { useState } from 'react';
import styles from '../css/resetPwd.module.css'
import { Input, Button, message } from 'antd';
import { findUser } from '../request/instance';

export default function ConfirmPassword(props) {
    // 用户输入的账号
    const [accountNumber, setAccountNumber] = useState('')
    // 判断用户是否输入内容
    const [isError, setIsError] = useState('')
    // 确认按钮点击事件
    const IsConfirm = async () => {
        if (accountNumber.trim() === '') {
            setIsError(() => "账号不能为空！")
        } else {
            setIsError(() => "")
            await findUser(accountNumber).then((res) => {
                if (res.data.code == 200) {
                    props.OnConfirmAccount()
                    localStorage.setItem('phone', res.data.phone)
                }else{
                    message.error(res.data.message)
                }
            })
        }
    }
    return <>
        <div className={styles.box2}>
            <Input placeholder="请输入账号" className={styles.inp} value={accountNumber} onInput={(e) => { setAccountNumber(() => e.target.value) }} />
            {isError && <p style={{ color: 'red', margin: '10px 0 0 20px' }}>{isError}</p>}
            <br />
            <Button type="primary" className={styles.btn} onClick={IsConfirm}>确认</Button>
        </div>
    </>
}